import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { TaskProcessPanel } from "../task/imgtxt/TaskProcessPanel";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Language } from "../../../../extend/language/Language";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ETaskStatus } from "../../../../Message/Game/ETaskStatus";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { TaskInfo } from "../../model/TaskInfo";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../../resource/ColorConfig";
//class CurTaskItem
    
    export  class CurTaskItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            buttonMode = true;
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            return;
        }

        /* internal  */initUI(): void
        {
            this._titleTxt = ObjCreate.createTextField("", 0, 0, -1, -1, null, GlobalStyle.getTextFormatDefaultFont(GlobalStyle.textFormat1));
            this._titleTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._titleTxt.selectable = false;
            this._titleTxt.width = 360;
            this._titleTxt.height = 20;
            addChild(this._titleTxt);
            this._taskProcessPanel = new TaskProcessPanel();
            addChild(this._taskProcessPanel);
            this._quickComBtn = new GButton();
            this._quickComBtn.styleName = "Button";
            this._quickComBtn.setSize(70, 22);
            this._quickComBtn.y = 0;
            this._quickComBtn.x = 250;
            this._quickComBtn.label = Language.getString(20655);
            this._quickComBtn.textField.filters = [FilterConst.nameGlowFilter];
            this._quickComBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onQuickComClickHandler);
            addChild(this._quickComBtn);
            return;
        }

        /* internal  */onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._taskInfo.status != ETaskStatus._ETaskStatusNotCompleted) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.SectarianTaskEndReq, this._taskInfo));
            }
            return;
        }

        /* internal  */onQuickComClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.SectarianTaskQuickEndReq, this._taskInfo));
            return;
        }

        public updateData(arg1: TaskInfo): void
        {
            this._taskInfo = arg1;
            this._titleTxt.htmlText = HTMLUtil.addColor(arg1.processStr + arg1.isCompleted, ColorConfig.instance.getItemColor(this._taskInfo.color).color);
            this._taskProcessPanel.updateData(this._titleTxt, this._taskInfo);
            if (this._taskInfo.status != ETaskStatus._ETaskStatusNotCompleted) 
            {
                if (contains(this._quickComBtn)) 
                {
                    removeChild(this._quickComBtn);
                }
            }
            else if (!contains(this._quickComBtn)) 
            {
                addChild(this._quickComBtn);
            }
            return;
        }

        public dispose(): void
        {
            this._taskInfo = null;
            this._taskProcessPanel.dispose();
            return;
        }

        public /* override */ get width(): number
        {
            return 360;
        }

        public /* override */ get height(): number
        {
            return 20;
        }

        /* internal */ /* var */_titleTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_taskInfo: TaskInfo;

        /* internal */ /* var */_taskProcessPanel: TaskProcessPanel;

        /* internal */ /* var */_quickComBtn: GButton;
    }
